﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class Issue : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.Params["IssueID"] != null)
            {
                string paramValue = Request.Params["IssueID"];
                int issueID = Convert.ToInt32(paramValue);

                RaisingStudio.Data.Providers.DataContext dc = new RaisingStudio.Data.Providers.DataContext();
                RaisingStudio.Data.Entities.Issue issue = dc.GetData<RaisingStudio.Data.Entities.Issue>(issueID);

                this.IssueID.Text = Convert.ToString(issue.IssueID);
                this.IssueID.Enabled = false;

                this.Title.Text = issue.Title;
                this.Status.Text = Convert.ToString(issue.Status);
                this.IssueType.Text = Convert.ToString(issue.IssueType);
                this.Owner.Text = issue.Owner;
                this.Progress.Text = Convert.ToString(issue.Progress);
                this.CreateTime.Text = Convert.ToString(issue.CreateTime);
                this.Locked.Checked = issue.Locked ?? false;
                this.Description.Text = issue.Description;
            }
        }
    }
    protected void Submit_Click(object sender, EventArgs e)
    {
        RaisingStudio.Data.Entities.Issue issue = new RaisingStudio.Data.Entities.Issue();
        if (!string.IsNullOrEmpty(this.IssueID.Text))
        {
            issue.IssueID = Convert.ToInt32(this.IssueID.Text);
        }
        issue.Title = this.Title.Text;
        if (!string.IsNullOrEmpty(this.Status.Text))
        {
            issue.Status = (RaisingStudio.Data.Entities.IssueStatus)Enum.Parse(typeof(RaisingStudio.Data.Entities.IssueStatus), this.Status.Text);
        }
        if (!string.IsNullOrEmpty(this.IssueType.Text))
        {
            issue.IssueType = (RaisingStudio.Data.Entities.IssueType)Enum.Parse(typeof(RaisingStudio.Data.Entities.IssueType), this.IssueType.Text);
        }
        issue.Owner = this.Owner.Text;
        if (!string.IsNullOrEmpty(this.Progress.Text))
        {
            issue.Progress = Convert.ToDecimal(this.Progress.Text);
        }
        if (!string.IsNullOrEmpty(this.CreateTime.Text))
        {
            issue.CreateTime = Convert.ToDateTime(this.CreateTime.Text);
        }
        issue.Locked = this.Locked.Checked;
        issue.Description = this.Description.Text;
        RaisingStudio.Data.Providers.DataContext dc = new RaisingStudio.Data.Providers.DataContext();
        dc.Save<RaisingStudio.Data.Entities.Issue>(issue);

        Response.Redirect("~/Default.aspx");
    }
}
